package com.lzhsite.technology.designPattern.command.CalculatorDemo;
/**
 * 系统需要支持命令的撤销(Undo)操作和恢复(Redo)操作。
 * @author lzhcode
 *
 */
public class ClientForCalculatorDemo {
	public static void main(String[] args) {
		IOperation operation = new Operation();
		AddCommand addCommand = new AddCommand(operation, 5);
		SubtractCommand subtractCommand = new SubtractCommand(operation, 3);

		Calculator calculator = new Calculator();
		calculator.setAddCommand(addCommand);
		calculator.setSubtractCommand(subtractCommand);

		calculator.addPressed();
		System.out.println("一次加法运算后的结果为：" + operation.getResult());

		calculator.subtractPressed();
		System.out.println("一次减法运算后的结果为：" + operation.getResult());

		calculator.undoPressed();
		System.out.println("撤销一次后的结果为：" + operation.getResult());

		calculator.undoPressed();
		System.out.println("再撤销一次后的结果为：" + operation.getResult());

		calculator.redoPressed();
		System.out.println("恢复操作一次后的结果为：" + operation.getResult());

		calculator.redoPressed();
		System.out.println("再恢复操作一次后的结果为：" + operation.getResult());
	}
}
